program euler_heun
implicit none
integer		::	i,j,n
real	::	h=0.25,y=1.0,x=0.0
n=2/h
write(1,*) x,y
open(1,file='euler1.dat')
do i=1,n
y=y+h*f(x,y)
x=x+h
write(1,*) x,y
end do
close(1)
y=1.0;x=0.0
h=0.5
n=2/h
write(2,*) x,y
open(2,file='euler2.dat')
do i=1,n
y=y+h*f(x,y)
x=x+h
write(2,*) x,y
end do
close(2)

open(3,file='heun1.dat')
h=0.25;x=0.0;y=1.0
n=2/h
write(3,*) x,y
do i=1,n
y=y+h*(f(x,y)+f(x+h,y+h*f(x,y)))/2
x=x+h
write(3,*) x,y
end do

close(3)
open(4,file='heun2.dat')
h=0.5;x=0.0;y=1.0
n=2/h
write(4,*) x,y
do i=1,n
y=y+h*(f(x,y)+f(x+h,y+h*f(x,y)))/2
x=x+h
write(4,*) x,y
end do
close(4)


contains
	function	f(x,y)
	real, intent(in)	::	x,y
	real 				::	f
	f=(1+2*x)*sqrt(y)
	end function
	
end program

